﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;
using StockFinder.Model.Constants;
using StockFinder.Model;
using Db4objects.Db4o.Config;

namespace StockFinder.Services.PriceAnalysis
{
    public class PriceAnalyserContainer
    {
        public void Run()
        {
            //1 load the prices from file
            // save the price database
            using (IObjectContainer database = Db4oEmbedded.OpenFile(GeCreateIEmbeddedConfiguration(),
                ApplicationConfiguation.ObjectDatabaseSRootDirectory + ObjectDatabaseFilenames.PRICE_HISTORY_DATABASE))
            {
                //get or create PriceHistoryContainer
                List<PriceHistoryDatabase> priceHistoryDatabases = database.Query<PriceHistoryDatabase>().ToList();

                if (priceHistoryDatabases == null || priceHistoryDatabases.Count == 0)
                {
                    throw new Exception("Could not find any PriceHistoryDatabases");
                }

                //should only be 1 price history container
                PriceHistoryDatabase priceHistoryDatabase = priceHistoryDatabases[0];

                
            }
        }

        private IEmbeddedConfiguration GeCreateIEmbeddedConfiguration()
        {
            IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
            //config.Common.ActivationDepth = 1;
            config.File.BlockSize = 8;

            return config;
        }
    }
}
